$(function(){
	var userNameInput = $('#userName');
	var passwordInput = $('#password');
	var userNameDiv = $('#userNameDiv');
	var passwordDiv = $('#passwordDiv');
	var userNameMsg = $('#userNameMsg');
	var passwordMsg = $('#passwordMsg');
	var userName = null;
	var password = null;
	passwordInput.on('change',function(){
		password = passwordInput.val();
		if(password != ''){
			passwordDiv.removeClass('has-error');
			passwordMsg.html('');
		}else{
			passwordDiv.removeClass('has-success').addClass('has-error');
			passwordMsg.html('<span class="help-block"><i class="fa fa-close"></i>请输入密码</span>');
		}
	});
	
	$('#sbmBtn').on('click',function(){
		userName = userNameInput.val();
		password = passwordInput.val();
		if(userName == null || userName == ''){
			userNameDiv.removeClass('has-success').addClass('has-error');
			userNameMsg.html('<span class="help-block"><i class="fa fa-close"></i>请输入手机号</span>');
			return;
		}
		if(password == null || password == ''){
			passwordDiv.removeClass('has-success').addClass('has-error');
			passwordMsg.html('<span class="help-block"><i class="fa fa-close"></i>请输入密码</span>');
			return;
		}
		Net.post({
			url:'/login',
			data:{
				userName:userName,
				password:password
			},
			success:function(resp){
				switch (resp.code) {
				case 0:
					ui.msg.success('登录成功');
					ui.go('/home');
					break;
				case 1:
					ui.msg.error(resp.msg);
					break;
				}
			}
		});
	});
	
	$(document).keypress(function(e) {
		if(e.which == 13) {
			$('#sbmBtn').click();
		}
	});
})